<?php
require_once(dirname(__FILE__) . '/../include/config.inc.php');
require_once "function.php";

//工单提交处理
$post_time = time();
$post_time2 = date("Y-m-d H:i:s", time());


$h = date("H", time());
$h = intval($h);
$d = date("d", time());
$d = intval($d);


// 列出系统中 抢单 任务
$sql_order_qiang = "SELECT id,manageid,post_time,apply_device,school,truename,mobile  FROM  `#@__order`  where    jindu='3' and mode='q' and manageid=''  and is_delete=0   order by id desc   ";
$dosql->Execute($sql_order_qiang);
while ($row_qiang = $dosql->GetArray()) {
    var_dump($row_qiang);
    exit;
    $orderid = $row_qiang['id'];
    $orderidname = date('Ymd', $row_qiang['post_time']) . "-" . $orderid;  //工单号
    $repairname = getRepairMode($row_qiang['apply_device']);  //任务名称
    $addtime = $row_qiang['post_time'];
    $school = $row_qiang['school'];
    $truename = $row_qiang['truename'];
    $mobile = $row_qiang['mobile'];
    $apply_time = date("Y-m-d H:i:s", $row_qiang['post_time']);
    //超过指定时间 后进行系统 指派模式
    if ($post_time - $addtime >$cfg_qiangout*60) {
        //列出 工程师 计算忙闲状态
        // 1 获取抢单的工程师

        $qiang_user = array();
        $user_do_num = array();
        $no_working_openid = array();
        $qiang_openid = "";
        $xian_arr = array();
        $xian_openid_arr = array();
        $dosql->Execute("SELECT `openid`,`id`,`truename` FROM  `#@__user`  WHERE level='3' and qiang='1'  ORDER BY id asc");
        while ($row_qiang = $dosql->GetArray()) {

            $user_id = $row_qiang['id'];
            //2 列出处理中的订单
            $do_num_count = 0;
            $do_order = $dosql->GetOne("select count(id) as num from `#@__order`  where jindu<5 and jindu>0  and FIND_IN_SET('$user_id',manageid) and is_delete=0 ");
            if (is_array($do_order) && isset($do_order['num'])) {
                $do_num_count = $do_order['num'];
            }
            //找出闲人
            if ($do_num_count == 0) {
                $no_working_openid[] = $row_qiang['openid'];
            }
            $row_qiang['do_num_count'] = $do_num_count;
            $user_do_num[] = $do_num_count;
            $qiang_user[] = $row_qiang;

        }
        //对相对空闲的工程师进行派单
        $zuixian = min($user_do_num); //获取最小的处理工单数量
        $xian_arr = array_keys($user_do_num, $zuixian);
        foreach ($xian_arr as $key => $val) {
            $xian_openid_arr[] = $qiang_user[$val];
        }
        //抽取随机人员
        $rndKey = array_rand($no_working_openid);
        $qiang_user = $xian_openid_arr[$rndKey];
        $qiang_openid=$qiang_user['openid'];
        $qiang_user_id=$qiang_user['id'];


    }
}




?>